<?php
/*
  Last Chance
  Copyright (c) 2008 Last Chance


  Released under the GNU General Public License

*/

  require('includes/application_top.php');

  $action = (isset($_GET['action']) ? $_GET['action'] : '');

  if (tep_not_null($action)) {
    switch ($action) {

      case 'save':
        if (isset($_GET['typeID'])) $order_type_id = tep_db_prepare_input($_GET['typeID']);

         $languages = tep_get_languages();
      for ($i=0; $i<sizeof($languages); $i++) {
            $language_id = $languages[$i]['id'];

   $sql_data_array = array('order_type_type' => tep_db_prepare_input($_POST['order_type_type']),
                           'order_type_name' => tep_db_prepare_input($_POST['order_type_name'][$language_id]),
                           'order_type_disc' => tep_db_prepare_input($_POST['order_type_disc'][$language_id]),
                           'language_id' => tep_db_prepare_input($language_id),
                           );

tep_db_perform(TABLE_ORDER_TYPE, $sql_data_array, 'update', 'order_type_id = \'' . $_POST['order_type_id'] . '\' and language_id = \'' . $language_id . '\'');
              }

           tep_redirect(tep_href_link(FILENAME_CREATE_ORDER_TYPE,'page=' . $_GET['page'] . '&typeID=' . $order_type_id));
              break;
      case 'insert':

         $languages = tep_get_languages();
      for ($i=0; $i<sizeof($languages); $i++) {
            $language_id = $languages[$i]['id'];
            $order_type_type = $_POST['order_type_type'];
            $order_type_name = $_POST['order_type_name'][$language_id];
            $order_type_disc = $_POST['order_type_disc'][$language_id];

            tep_db_query("insert into " . TABLE_ORDER_TYPE . " (order_type_type, order_type_name, order_type_disc, language_id) values ('" . tep_db_input($order_type_type) . "',  '" . tep_db_input($order_type_name) . "', '" . tep_db_input($order_type_disc) . "', '" . tep_db_input($language_id). "')");
        }

           tep_redirect(tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $order_type_id));
        break;
      case 'deleteconfirm':
        $typeID = tep_db_prepare_input($_GET['typeID']);
        tep_db_query("delete from " . TABLE_ORDER_TYPE . " where order_type_id = '" . tep_db_input($typeID) . "'");

        tep_redirect(tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page']));
        break;
      case 'delete':
        $typeID = tep_db_prepare_input($_GET['typeID']);

           $remove_status = true;

        break;
    }
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script type="text/javascript" src="includes/menu.js"></script>
<script type="text/javascript" src="includes/general.js"></script>
</head>
<body bgcolor="#FFFFFF" onload="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">

                 <td class="dataTableHeadingContent"><?php echo TEXT_INFO_ORDER_TYPE_TYPE; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CREATE_ORDERS_ADMIN; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
<?php

  $order_type_query_raw = "select order_type_id, language_id, order_type_type, order_type_name, order_type_disc from " . TABLE_ORDER_TYPE . " where language_id ='" . $languages_id . "' order by order_type_name";
  $order_type_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $order_type_query_raw, $order_type_query_numrows);
  $order_type_query = tep_db_query($order_type_query_raw);
  while ($order_type = tep_db_fetch_array($order_type_query)) {
    if ((!isset($_GET['typeID']) || (isset($_GET['typeID']) && ($_GET['typeID'] == $order_type['order_type_id']))) && !isset($oInfo) && (substr($action, 0, 3) != 'new')) {
      $oInfo = new objectInfo($order_type);
    }

    if (isset($oInfo) && is_object($oInfo) && ($order_type['order_type_id'] == $oInfo->order_type_id)) {
      echo '                  <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id . '&action=edit') . '\'">' . "\n";
    } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $order_type['order_type_id']) . '\'">' . "\n";
    }

    if ($order_type['order_type_name_sort'] == '1') {
      echo '                <td class="dataTableContent">' . $order_type['order_type_type'] . '</td>' . '<td class="dataTableContent"><b>' . $order_type['order_type_name'] . ' (' . TEXT_DEFAULT . ')</b></td>' . "\n";
    } else {
      echo '                <td class="dataTableContent">' . $order_type['order_type_type'] . '</td>' . '<td class="dataTableContent">' . $order_type['order_type_name'] . '</td>' . "\n";
    }
?>
                <td class="dataTableContent" align="right"><?php if (isset($oInfo) && is_object($oInfo) && ($order_type['order_type_id'] == $oInfo->order_type_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $order_type['order_type_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
  }
?>
              <tr>
                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $order_type_split->display_count($order_type_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_ORDER_TYPE); ?></td>
                    <td class="smallText" align="right"><?php echo $order_type_split->display_links($order_type_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page']); ?></td>
                  </tr>
<?php
  if (empty($action)) {
?>
                  <tr>
                    <td colspan="2" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&action=new') . '">' . tep_image_button('button_insert.gif', IMAGE_INSERT) . '</a>'; ?></td>
                  </tr>
<?php
  }
?>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();

  switch ($action) {
    case 'new':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_ORDER_TYPE . '</b>');

      $contents = array('form' => tep_draw_form('status', FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&action=insert', 'post')) ;
      $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);

      $order_type_inputs_string = '';
      $order_type_inputs_string .= '<br>' . TEXT_INFO_ORDER_TYPE_TYPE. ' &nbsp;'. tep_draw_input_field('order_type_type', $oInfo->order_type_type);

         for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
       $order_type_inputs_string .= '<br>'. tep_image(HTTP_SERVER . DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' .
                '<br>' . TEXT_INFO_ORDER_TYPE_NAME . tep_draw_input_field('order_type_name[' . $languages[$i]['id'] . ']', tep_get_order_type_name($_GET['typeID'], $languages[$i]['id'])) .
                '<br>' . TEXT_INFO_ORDER_TYPE_DISC . tep_draw_textarea_field('order_type_disc[' . $languages[$i]['id'] . ']',  '', 20, 3, tep_get_order_type_disc($_GET['typeID'], $languages[$i]['id']), '');
    }
    $order_type_inputs_string .= '<br>'. tep_image(HTTP_SERVER . DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' .
    $contents[] = array('text' => '<br>' . $order_type_inputs_string);      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_insert.gif', IMAGE_INSERT) . ' <a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    case 'edit':
     $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_ORDER_TYPE . '</b>');
     $contents = array('form' => tep_draw_form('status', FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id  . '&action=save')) ;
     $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
      $languages = tep_get_languages();
      if (!isset($order_type_inputs_string)) {
         $order_type_inputs_string = '';
       }
     $order_type_inputs_string .= '<br>' . TEXT_INFO_ORDER_TYPE_TYPE. ' &nbsp;'. tep_draw_input_field('order_type_type', $oInfo->order_type_type);

        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
      $order_type_inputs_string .= '<br>'. tep_image(HTTP_SERVER . DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' .
               '<br>' . TEXT_INFO_ORDER_TYPE_NAME . tep_draw_input_field('order_type_name[' . $languages[$i]['id'] . ']', tep_get_order_type_name($_GET['typeID'], $languages[$i]['id'])) .
               '<br>' . TEXT_INFO_ORDER_TYPE_DISC . tep_draw_textarea_field('order_type_disc[' . $languages[$i]['id'] . ']',  '', 20, 3, tep_get_order_type_disc($_GET['typeID'], $languages[$i]['id']), '');
    }

    $contents[] = array('text' => '<br>' . $order_type_inputs_string);
    $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;

    case 'delete':
      $heading[] = array('text' => '<b>' . TEXT_INFO_DELETE_INTRO . '</b>');

      $contents = array('form' => tep_draw_form('status', FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id  . '&action=deleteconfirm')) ;
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
      $contents[] = array('text' => '<br><b>' . $oInfo->order_type_name . '</b>');
      if ($remove_status) $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    default:
      if (isset($oInfo) && is_object($oInfo)) {
        $heading[] = array('text' => '<b>' . $oInfo->order_type_name . '</b>');

        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_CREATE_ORDER_TYPE, 'page=' . $_GET['page'] . '&typeID=' . $oInfo->order_type_id . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');

        $order_type_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $order_type_inputs_string .= '<br>' . tep_image(HTTP_SERVER . DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_get_order_type_name($oInfo->order_type_id, $languages[$i]['id']);
       }

        $contents[] = array('text' => $order_type_inputs_string);
      }
      break;
  }

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
